package com.example.demo.service.Impl;


import com.example.demo.dao.ICd;
import com.example.demo.model.Cd;
import com.example.demo.service.ICdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator 张喜英
 */

@Service
public class CdServiceImpl implements ICdService{

    @Autowired
    private ICd cdMapper;
    @Override
    public int insertCd(Cd cd){
        int cdValue=0;
        System.out.println(cd.getCdid());
        Cd cd1=new Cd();
        cd1.setCdid(cd.getCdid());
        List<Cd> getU=cdMapper.getAllCd(cd1);
        if(getU.size()>0){
            cdValue=-1;

        }else{
            cdValue=cdMapper.insertCd(cd);
        }

        return cdValue;
    }

    @Override
    public List<Cd> getAllCd(Cd cd) {


        return cdMapper.getAllCd(cd);
    }

    @Override
    public int updateCd(Cd cd) {
        int cdValues=0;
        if(cd.getCdid()!=0){



            cdValues=cdMapper.updateCd(cd);
        }
        return cdValues;
    }

    @Override
    public int deleteCd(Cd cd) {
        int cdValues=0;
        if(cd.getCdid()!=0)
        {
            //主键是否与其他表有关联

           cdValues=cdMapper.deleteCd(cd);
        }
        return cdValues;
    }

    @Override
    public Cd getCd(Cd cd) {
        Cd cd1=new Cd();
        if(cd.getCdid()!=0){
            cd1=cdMapper.getCd(cd);
        }
        return cd1;
    }

}
